package cn.sc.summer.calculate.filter;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.sc.summer.calculate.annotation.JobExecution;
import cn.sc.summer.calculate.mapper.SysLogMapper;
import cn.sc.summer.constant.util.DateUtilX;
import cn.sc.summer.log.po.SysLog;
import cn.sc.summer.mybatis.annotation.dynamicdatasource.DataSource;
import cn.sc.summer.mybatis.enums.DataSourceEnum;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 类名：api访问日志清理
 *
 * @author a-xin
 * @date 2024/3/19 16:44
 */
@Slf4j
@Service
@DisallowConcurrentExecution
@JobExecution("清理api请求日志")
public class SysLogFilter extends LogFilter {

    @Resource
    private SysLogMapper sysLogMapper;

    /**
     * 清理日志信息
     */
    @Override
    @DataSource(DataSourceEnum.POST_GRE_SQL)
    public void cleanUpLogs() {
        sysLogMapper.delete(new LambdaQueryWrapper<SysLog>()
                .lt(SysLog::getCreateTime, DateUtilX.offsetDay(new Date(), -7)));
    }

}
